﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Jason.Client.ComponentModel;
using Jason.Client.Runtime;
using Jason.Factories;
using Jason.Runtime;

namespace SampleApp.MvcBackend
{
    public class JasonConfig
    {
        public static void Initialize( String pathToScanForAssemblies, String assemblySelectPattern, IWindsorContainer container )
        {
			container.Register( Component.For<ICommandHandlersProvider>().ImplementedBy<DefaultCommandHandlersProvider>() );
			container.Register( Component.For<IWorkerServiceClientFactory>().ImplementedBy<DefaultWorkerServiceClientFactory>() );

            //serve solo per WebAPI
            //container.Register( Castle.MicroKernel.Registration.Component.For<JasonController>().LifeStyle.Is( LifestyleType.Transient ) );

            var jasonConfig = new Jason.Client.InProcess.JasonInProcessConfiguration(
                pathToScanForAssemblies: pathToScanForAssemblies,
                assemblySelectPattern: assemblySelectPattern )
            {
                RegisterAsTransient = ( c, i ) =>
                {
                    container.Register
                    (
                        Castle.MicroKernel.Registration.Component.For( c )
                            .ImplementedBy( i )
                            .LifeStyle.Is( Castle.Core.LifestyleType.Transient )
                    );
                }
            };

            jasonConfig.Initialize();
        }
    }
}